package com.jlastu.znb.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.jlastu.znb.R;
import com.jlastu.znb.constan.Constance;
import com.jlastu.znb.entity.HotNews;
import com.jlastu.znb.entity.ShopUserData;

import java.text.SimpleDateFormat;
import java.util.Date;

public class PublishNongJiActivity extends Activity {
    String currPage;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish);
        currPage = getIntent().getStringExtra("page");
        EditText ed = findViewById(R.id.ed_text);
        TextView pub = findViewById(R.id.tv_publish);
        TextView tvTitle = findViewById(R.id.tv_title);
        tvTitle.setText(currPage);
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 格式化日期的格式
        String formattedDate = sdf.format(date);
        pub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content =ed.getText().toString();
                if(Constance.PUBLISH_NONGJI.equals(currPage)) {//发布热点新闻
                    HotNews hotNews =new HotNews("https://pics4.baidu.com/feed/c2cec3fdfc039245b7fe0c97edaf8ecc7c1e25ac.jpeg@f_auto?token=ca1c3a5f793df61080fa757b5a551138",
                            content,formattedDate,"0");
                    Intent intent = new Intent();
                    intent.putExtra("data",hotNews);
                    setResult(0,intent);
                    finish();
                }else {//发布农友圈
                    String imageUrl = "https://t7.baidu.com/it/u=4031278332,3112565627&fm=193&f=GIF";
                    ShopUserData shopUserData = new ShopUserData(content,
                            "https://t7.baidu.com/it/u=1148322283,2872513312&fm=193&f=GIF",
                            "我的名字", formattedDate, false, imageUrl, 123, 890
                    );
                    shopUserData.setUserId("-1");
                    Intent intent = new Intent();
                    intent.putExtra("data",shopUserData);
                    setResult(1,intent);
                    finish();
                }
            }
        });

    }

}
